<?php
if(isset($_POST['UpdateCode']))
{
	$sptdd=explode("/",$_POST['enddate']);
	$expdate=$sptdd[2]."-".$sptdd[0]."-".$sptdd[1];
	
	$ssptdd=explode("/",$_POST['startdate']);
	$startdate=$ssptdd[2]."-".$ssptdd[0]."-".$ssptdd[1];
	
	$tot=mysql_num_rows(mysql_query("select * from couponcode"));
	if($tot>0)
	{
		$str="update couponcode set title='".$_POST['title']."',code='".$_POST['promocode']."',";
		$str.="startdate='".$startdate."',enddate='".$expdate."',type='".$_POST['type']."',";
		$str.="discount='".$_POST['discount']."'  where id='".$_GET['edit']."'";
	}
	else
	{
		$str="insert into couponcode set title='".$_POST['title']."',code='".$_POST['promocode']."',";
		$str.="startdate='".$startdate."',enddate='".$expdate."',type='".$_POST['type']."',discount='".$_POST['discount']."'";
	}
	$exe=mysql_query($str);
	echo "<script>window.locaiton='index.php?tc=couponcode&succ';</script>";
}
$edit=mysql_fetch_array(mysql_query("select * from couponcode"));
?>
<link type="text/css" rel="stylesheet" href="js/dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="js/dhtmlgoodies_calendar.js?random=20060118"></script>
<form action="" method="post" name="form1">
<table border="0" width="100%" align="center">
<tr>
	<td width="45%" align="left"><span style="color:#1B78B7; font-size:14px; font-weight:bold">Promotional code</span>
    </td>
	<td width="40%" align="right">&nbsp;
    </td>
	<td width="15%" align="right">&nbsp;</td>
</tr>
<tr>
	<td background="images/topline.gif" colspan="3" height="11"></td>
</tr>  
<tr>
	<td colspan="3" height="11">
    &nbsp;<?php if(isset($_GET['succ'])){echo "Successfully updated";}?>
    </td>
</tr>
<tr>
  <td colspan="3" height="11"><table width="70%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td width="27%" align="left" valign="middle">&nbsp;</td>
      <td width="73%" align="left" valign="middle">&nbsp;</td>
    </tr>
    <tr>
      <td align="left" valign="middle">Title</td>
      <td align="left" valign="middle">
      <input type="text" name="title" id="title" class="txtborder" style="width:150px;" value="<?php echo $edit['title']?>"/></td>
    </tr>
    <tr>
      <td align="left" valign="middle">&nbsp;</td>
      <td align="left" valign="middle">&nbsp;</td>
    </tr>
    <tr>
      <td align="left" valign="middle">Promotional code</td>
      <td align="left" valign="middle">
      <input type="text" name="promocode" id="promocode" class="txtborder" value="<?php echo $edit['code']?>" style="width:150px;"/></td>
    </tr>
    <tr>
      <td align="left" valign="middle">&nbsp;</td>
      <td align="left" valign="middle">&nbsp;</td>
    </tr>
    <tr>
      <td align="left" valign="middle">starting date</td>
      <td align="left" valign="middle">
      <?php 
		$spt=explode("-",$edit['startdate']);
		$expdds=$spt[1]."/".$spt[2]."/".$spt[0];
		?>
		<input type="text" name="startdate" value="<?php echo $expdds;?>" onclick="displayCalendar(document.form1.startdate,'mm/dd/yyyy',this)" id="startdate" style="width:80px;" class="txtborder"/>
		<img src="../images/cal.gif" onclick="displayCalendar(document.form1.startdate,'mm/dd/yyyy',this)" border="0" /></td>
    </tr>
    <tr>
      <td align="left" valign="middle">&nbsp;</td>
      <td align="left" valign="middle">&nbsp;</td>
    </tr>
    <tr>
      <td align="left" valign="middle">end date</td>
      <td align="left" valign="middle">
      <?php 
		$spt=explode("-",$edit['enddate']);
		$expdds=$spt[1]."/".$spt[2]."/".$spt[0];
		?>
		  <input type="text" name="enddate" value="<?php echo $expdds;?>" onclick="displayCalendar(document.form1.enddate,'mm/dd/yyyy',this)" id="enddate" style="width:80px;" class="txtborder"/>
		<img src="../images/cal.gif" onclick="displayCalendar(document.form1.enddate,'mm/dd/yyyy',this)" border="0" /></td>
    </tr>
    <tr>
      <td align="left" valign="middle">&nbsp;</td>
      <td align="left" valign="middle">&nbsp;</td>
    </tr>
    <tr>
      <td align="left" valign="middle">Type</td>
      <td align="left" valign="middle">
      <select name="type" id="type" class="txtborder" style="width:150px;">
        <option <?php if($edit['type']=="Percentage"){echo "selected";}?> value="Percentage">Percentage</option>
        <option <?php if($edit['type']=="Amount"){echo "selected";}?> value="Amount">Amount</option>
        </select>
      </td>
    </tr>
    <tr>
      <td align="left" valign="middle">&nbsp;</td>
      <td align="left" valign="middle">&nbsp;</td>
    </tr>
    <tr>
      <td align="left" valign="middle">Discount</td>
      <td align="left" valign="middle">
      <input type="text" name="discount" id="discount" value="<?php echo $edit['discount']?>" class="txtborder" style="width:150px;"/></td>
    </tr>
    <tr>
      <td align="left" valign="middle">&nbsp;</td>
      <td align="left" valign="middle">&nbsp;</td>
    </tr>
    <tr>
      <td align="left" valign="middle">&nbsp;</td>
      <td align="left" valign="middle">
      <input type="submit" name="UpdateCode" class="buttonbg" value="Update" />
      </td>
    </tr>
  </table></td>
</tr>
<tr>
  <td colspan="3" height="11">&nbsp;</td>
</tr>    
</table>
</form>
    